<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="困难人员id" prop="personId">
      <el-input v-model="dataForm.personId" placeholder="困难人员id"></el-input>
    </el-form-item>
    <el-form-item label="保障政策" prop="safeguardPolicy">
      <el-input v-model="dataForm.safeguardPolicy" placeholder="保障政策"></el-input>
    </el-form-item>
    <el-form-item label="具体描述" prop="description">
      <el-input v-model="dataForm.description" placeholder="具体描述"></el-input>
    </el-form-item>
    <el-form-item label="网格员" prop="gridMember">
      <el-input v-model="dataForm.gridMember" placeholder="网格员"></el-input>
    </el-form-item>
    <el-form-item label="网格员电话" prop="gridPhone">
      <el-input v-model="dataForm.gridPhone" placeholder="网格员电话"></el-input>
    </el-form-item>
    <el-form-item label="困难情形" prop="difficultyType">
      <el-input v-model="dataForm.difficultyType" placeholder="困难情形"></el-input>
    </el-form-item>
    <el-form-item label="关爱类型" prop="solicitudeType">
      <el-input v-model="dataForm.solicitudeType" placeholder="关爱类型"></el-input>
    </el-form-item>
    <el-form-item label="关爱举措" prop="solicitude Measures">
      <el-input v-model="dataForm.solicitude Measures" placeholder="关爱举措"></el-input>
    </el-form-item>
    <el-form-item label="状态（0待核查  1已核查 2未通过  3上报）" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态（0待核查  1已核查 2未通过  3上报）"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          personId: '',
          safeguardPolicy: '',
          description: '',
          gridMember: '',
          gridPhone: '',
          difficultyType: '',
          solicitudeType: '',
          solicitude Measures: '',
          status: ''
        },
        dataRule: {
          personId: [
            { required: true, message: '困难人员id不能为空', trigger: 'blur' }
          ],
          safeguardPolicy: [
            { required: true, message: '保障政策不能为空', trigger: 'blur' }
          ],
          description: [
            { required: true, message: '具体描述不能为空', trigger: 'blur' }
          ],
          gridMember: [
            { required: true, message: '网格员不能为空', trigger: 'blur' }
          ],
          gridPhone: [
            { required: true, message: '网格员电话不能为空', trigger: 'blur' }
          ],
          difficultyType: [
            { required: true, message: '困难情形不能为空', trigger: 'blur' }
          ],
          solicitudeType: [
            { required: true, message: '关爱类型不能为空', trigger: 'blur' }
          ],
          solicitude Measures: [
            { required: true, message: '关爱举措不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态（0待核查  1已核查 2未通过  3上报）不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/generator/tbldifficultydata/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.personId = data.tblDifficultyData.personId
                this.dataForm.safeguardPolicy = data.tblDifficultyData.safeguardPolicy
                this.dataForm.description = data.tblDifficultyData.description
                this.dataForm.gridMember = data.tblDifficultyData.gridMember
                this.dataForm.gridPhone = data.tblDifficultyData.gridPhone
                this.dataForm.difficultyType = data.tblDifficultyData.difficultyType
                this.dataForm.solicitudeType = data.tblDifficultyData.solicitudeType
                this.dataForm.solicitude Measures = data.tblDifficultyData.solicitude Measures
                this.dataForm.status = data.tblDifficultyData.status
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/tbldifficultydata/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'personId': this.dataForm.personId,
                'safeguardPolicy': this.dataForm.safeguardPolicy,
                'description': this.dataForm.description,
                'gridMember': this.dataForm.gridMember,
                'gridPhone': this.dataForm.gridPhone,
                'difficultyType': this.dataForm.difficultyType,
                'solicitudeType': this.dataForm.solicitudeType,
                'solicitude Measures': this.dataForm.solicitude Measures,
                'status': this.dataForm.status
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
